﻿using System;
using System.ComponentModel;
using System.Windows;


namespace ThePresenter.IO
{
	public abstract class AbstractFormat : IFormat
	{
		#region Fields
		int _TotalSlides;

		int _SlidesDone;
		#endregion


		#region IFormat Members
		/// <summary>
		/// Gets the filter that is shown in the <see cref="Microsoft.Win32.OpenFileDialog"/> and <see cref="Microsoft.Win32.SaveFileDialog"/> dialogs.
		/// If is null, this format does not support writing or reading to / from file.
		/// Can be null.
		/// </summary>
		/// <value>The filter shown in the dialogs.</value>
		public abstract string Filter { get; }

		/// <summary>
		/// Gets the configuration object.
		/// Can be null.
		/// </summary>
		/// <value>The configuration object.</value>
		public virtual DependencyObject Configuration
		{
			get { return null; }
		}

		/// <summary>
		/// Gets a value indicating whether this format supports progress reporting.
		/// </summary>
		/// <value><c>true</c> if this format supports progress reporting; otherwise, <c>false</c>.</value>
		public virtual bool SupportsProgressReporting
		{
			get { return false; }
		}

		/// <summary>
		/// If <seealso cref="SupportsProgressReporting"/>, then gets the total number of slides.
		/// </summary>
		/// <value>The total slides.</value>
		public virtual int TotalSlides
		{
			get
			{
				if (SupportsProgressReporting)
					return _TotalSlides;
				else
					throw new NotSupportedException();
			}
			protected set
			{
				if (_TotalSlides != value)
				{
					_TotalSlides = value;
					OnPropertyChanged("TotalSlides");
				}
			}
		}

		/// <summary>
		/// If <seealso cref="SupportsProgressReporting"/>, then gets the current count of processed slides.
		/// </summary>
		/// <value>The total slides.</value>
		public virtual int SlidesDone
		{
			get
			{
				if (SupportsProgressReporting)
					return _SlidesDone;
				else
					throw new NotSupportedException();
			}
			protected set
			{
				if (_SlidesDone != value)
				{
					_SlidesDone = value;
					OnPropertyChanged("SlidesDone");
				}
			}
		}
		#endregion


		#region INotifyPropertyChanged Members
		/// <summary>
		/// Raises the <see cref="E:PropertyChanged"/> event.
		/// </summary>
		/// <param name="propertyName">The name of the property that changed.</param>
		protected void OnPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}

		/// <summary>
		/// Occurs when a property value changes.
		/// </summary>
		public event PropertyChangedEventHandler PropertyChanged;
		#endregion
	}
}
